<?php
class RegisterAction extends Action{
	public function index(){
		$this->display();
	}
	
	//验证码生成
	public function verify()
    {
		$type = isset($_GET['type'])?$_GET['type']:'gif';
        import("@.ORG.Image");
        Image::buildImageVerify(4,1,$type);
    }
    
    //注册
    public function regedit(){
    	if($_SESSION["verify"]!=md5($_POST["verify"])){
    		$this->assign('errmsg',"验证码错误!");
    		$this->display("index");
    		exit();
    	}
        import("@.ORG.Input");
    	$suserModel = D("suser");
    	$storeModel = D("store");
        $suserName = Input::getVar(trim($_POST["suser_name"]));
    	$result_suser = $suserModel->field("suser_id")->where("suser_name='".$suserName."'")->find();
        
        if($result_suser){
            $this->assign('errmsg',"此域名已经存在!请重新输入域名");
            $this->display("index");
            exit();
        }
        $dataSuser["suser_name"]   =  Input::getVar(trim($_POST["suser_name"]));
		$dataSuser["suser_password"]   =  md5(trim($_POST["suser_password"]));
		$dataSuser["suser_pointcard"]  =  100;
		$dataSuser["suser_totlepointcard"] = 100;
		$addSuserResult = $suserModel->add($dataSuser);
        $suer = $suserModel->field("suser_id")->where("suser_name='".Input::getVar(trim($_POST["suser_name"]))."'")->find();
		if($$suer!==false){
			$dataStore["store_mid"]   	 =  $suer['suser_id'];
			$dataStore["store_static"]   =  0;
			$dataStore["store_recommend"]   =  0;
			$addStoreResult = $storeModel->add($dataStore);
			if($addStoreResult!==false){
				$this->assign('username',$suserName);
				$this->display("registerSuccess");
			}else{
				$this->assign('errmsg',$storeModel->getDbError());
				$suserModel->rollback();
			}
		}else{
			$this->assign('errmsg',$suserModel->getDbError());
			$suserModel->rollback();
		}
    }
}
?>